package com.example.arena;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 
 * @author Dani
 * This is a very fun game about distributing stats points. No, seriously,
 * you distribute here the points for the game. The activity tends to get disorganized
 * by itself, so... it may look a little odd... 
 * 
 */
public class StatsActivity extends Activity {
	//First of all, the declarations
private int axe=0;
private int sword=0;
private int spear=0;
private int points=12;

private TextView txtAxe;
private TextView txtSword;
private TextView txtSpear;
private TextView txtPoints;

private Button btnAddAxe;
private Button btnQuitAxe;
private Button btnAddSword;
private Button btnQuitSword;
private Button btnAddSpear;
private Button btnQuitSpear;
private Button btnReady;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_stats);
		
		//Associate all the elements
		 txtAxe = (TextView) findViewById(R.id.txtAxe);
		 txtSword = (TextView) findViewById(R.id.txtSword);
		 txtSpear = (TextView) findViewById(R.id.txtSpear);
		 txtPoints = (TextView) findViewById(R.id.txtPoints);
		 btnAddAxe = (Button) findViewById(R.id.btnAddAxe);
		 btnQuitAxe = (Button) findViewById(R.id.btnQuitAxe);
		 btnAddSword = (Button) findViewById(R.id.btnAddSword);
		 btnQuitSword = (Button) findViewById(R.id.btnQuitSword);
		 btnAddSpear = (Button) findViewById(R.id.btnAddSpear);
		 btnQuitSpear = (Button) findViewById(R.id.btnQuitSpear);
		 btnReady = (Button) findViewById(R.id.btnReady);
		
		 //The event when you click any of the stats button
		 btnAddAxe.setOnClickListener(new View.OnClickListener() {
		   	    public void onClick(View view) {
		   	    	if (axe < 9 && points > 0){
		   	    		axe+=1;
		   	    		points-=1;
		   	    		txtAxe.setText(String.valueOf(axe));
		   	    		txtPoints.setText(String.valueOf(points));
		   	    	}
		   	    }
		   	});
		
		 btnAddSword.setOnClickListener(new View.OnClickListener() {
		   	    public void onClick(View view) {
		   	    	if (sword < 9 && points > 0){
		   	    		sword+=1;
		   	    		points-=1;
		   	    		txtSword.setText(String.valueOf(sword));
		   	    		txtPoints.setText(String.valueOf(points));
		   	    	}
		   	    }
		   	});
		 
		 btnAddSpear.setOnClickListener(new View.OnClickListener() {
		   	    public void onClick(View view) {
		   	    	if (spear < 9 && points > 0){
		   	    		spear+=1;
		   	    		points-=1;
		   	 		txtSpear.setText(String.valueOf(spear));
	   	    		txtPoints.setText(String.valueOf(points));
		   	    	}
		   	    }
		   	});
		 
		 btnQuitAxe.setOnClickListener(new View.OnClickListener() {
		   	    public void onClick(View view) {
		   	    	if (axe > 0 && points < 12){
		   	    		axe-=1;
		   	    		points+=1;
		   	    		txtAxe.setText(String.valueOf(axe));
		   	    		txtPoints.setText(String.valueOf(points));
		   	    	}
		   	    }
		   	});
		 
		 btnQuitSword.setOnClickListener(new View.OnClickListener() {
		   	    public void onClick(View view) {
		   	    	if (sword > 0 && points < 12){
		   	    		sword-=1;
		   	    		points+=1;
		   	 		txtSword.setText(String.valueOf(sword));
	   	    		txtPoints.setText(String.valueOf(points));
		   	    	}
		   	    }
		   	});
		 
		 btnQuitSpear.setOnClickListener(new View.OnClickListener() {
		   	    public void onClick(View view) {
		   	    	if (spear > 0 && points < 12){
		   	    		spear-=1;
		   	    		points+=1;
		   	 		txtSpear.setText(String.valueOf(spear));
	   	    		txtPoints.setText(String.valueOf(points));
		   	    	}
		   	    }
		   	});
		 
		 
		 //And the event when you click the Ready button
		 btnReady.setOnClickListener(new View.OnClickListener() {
		   	    public void onClick(View view) {
		   	    	//If all points are set, then we start the activity sending the values with putExtra
		   	    	if ( points == 0){
		   	    		
		   	  Intent intent = new Intent(StatsActivity.this, FightActivity.class);
		   	  intent.putExtra("AxePoints", axe);
		   	  intent.putExtra("SwordPoints", sword);
		   	  intent.putExtra("SpearPoints", spear);
		   	  startActivity(intent);
		   	  
		   	    	}else{
		   	    		//If all points aren't set, a toast with this text will appear
		   	    		 Toast.makeText(getApplicationContext(), "You must spend all your points to play. You have points left.", Toast.LENGTH_SHORT).show();
		  
		   	    	}
		   	    }
		   	});
		 
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.stats, menu);
		return true;
	}

}
